#include <stdio.h>
#include <malloc.h>
#define INF 32767				//定义∞
#define	MAXV 100				//最大顶点个数
typedef char InfoType;

//以下定义邻接矩阵类型
typedef struct
{	int no;						//顶点编号
	InfoType info;				//顶点其他信息
} VertexType;					//顶点类型
typedef struct
{	int edges[MAXV][MAXV];		//邻接矩阵数组
	int n,e;					//顶点数，边数
	VertexType vexs[MAXV];		//存放顶点信息
} MatGraph;						//完整的图邻接矩阵类型


//------------------------------------------------------------
//----邻接矩阵的基本运算算法----------------------------------
//------------------------------------------------------------
void CreateMat(MatGraph &g,int A[MAXV][MAXV],int n,int e) //创建图的邻接矩阵
{
	int i,j;
	g.n=n; g.e=e;
	for (i=0;i<g.n;i++)
		for (j=0;j<g.n;j++)
			g.edges[i][j]=A[i][j];
}
void DispMat(MatGraph g)	//输出邻接矩阵g
{
	int i,j;
	for (i=0;i<g.n;i++)
	{
		for (j=0;j<g.n;j++)
			if (g.edges[i][j]!=INF)
				printf("%4d",g.edges[i][j]);
		else
			printf("%4s","∞");
		printf("\n");
	}
}



void DeleteEdge(MatGraph &g,int u,int v)
{
	if (g.edges[u][v] == 0)
		printf("图中没有此边!\n");
	else
	{	g.edges[u][v] = 0;
		g.e--;
		printf("删除成功！\n");
	}
}



int GetOutdegree(MatGraph &g, int p)
{	int degree = 0;
	for (int i = 0; i < g.n; i++)
	{	if (g.edges[p][i] == 1)
		degree++;
	}
	return degree;
	
}

int main()
{
	MatGraph g9p3;
	int a9p3[MAXV][MAXV] = {
		{0,1,0,1,0},//0
		{0,0,1,1,0},//1
		{0,0,0,1,1},//2
		{0,0,0,0,0},//3
		{1,0,0,1,0} //4
	};
	int n9p3 = 5;
	int e9p3 = 8;
	CreateMat(g9p3,a9p3,n9p3,e9p3);
	DispMat(g9p3);
	
	int x9p3 = 0,y9p3 = 0;
	printf("删除两点之间的边：\n");
	scanf("%d%d",&x9p3,&y9p3);
	DeleteEdge(g9p3,x9p3,y9p3);
	DispMat(g9p3);
	
	printf("计算某点的出度:>");
	scanf("%d",&x9p3);
	int num = GetOutdegree(g9p3,x9p3);
	printf("出度：%d\n",num);
	return 0;
}

